import netCDF4 as nc
from pynctools import pynctools

def pyncread(file,var,stride='[:]', mask=None):
    '''
    usage pyncread(file, var, stride=[:], mask=None)
        
    file   = filename
    var    = variable name
    stride = data string (default: full)
    mask   = data mask
    
    Author: Vihang Bhatt 
    Email : bhatt.vihang@gmail.com 
    '''
    
    fin=nc.Dataset(file,'r','NETCDF3_CLASSIC')
    
    if 'dimensions' in dir(fin.variables[var]):
       dimensions = fin.variables[var].dimensions
       shape      = fin.variables[var].shape
    else:
       dimensions = None
       shape      = None
       
    att_name=fin.variables[var].ncattrs()
    att_value=[]
    
    for name in att_name:
        value=getattr(fin.variables[var],name)
    
        if type(value) is str:
           att_value+=value
        else:
           att_value+={value}

    if '_FillValue' in att_name:
         att_name+={'FillValue'}
         att_value+={getattr(fin.variables[var],'_FillValue')}

#for ROMS COMPATIBILITY ADD FEW MORE ATTRIBUTES
    att_name+={'name'}
    att_value+={var}                


    data=eval('fin.variables[var]'+stride)


#closing file    
    fin.close()
    return pynctools(data, att_name, att_value, dimensions, shape, mask)
        
    
    
